﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace flattiverseGameClient
{
    public class LoginControlViewModel : Helper.ViewModelBase
    {
        #region variables
        private Flattiverse.Connector _connector;

        public ICommand LoginCmd;
        public ICommand LogoutCmd;

        #region getter/setter

        #endregion getter/setter
        #endregion variables

        #region Methodes
        public void Login()
        {

            IsLoggedIn = true;
            
            AccountName = _connector.Account.Name;
            Platform = _connector.Account.Platform.ToString();
        }

        public void LogOut()
        {
            IsLoggedIn = false;
        }
        #endregion Methoes

        #region constructor
        /// <summary>
        /// needed for blend
        /// </summary>
        public LoginControlViewModel()
        {
            //_connector = new Flattiverse.Connector();

            LoginCmd = new LoginCommand(this);
            LogoutCmd = new LogoutCommand(this);

            _isLoggedIn = false;
            _userName = "Hoschi81";
            _password = "password!1";
        }

        /// <summary>
        /// creates a new instance of LoginControlViewModel
        /// </summary>
        /// <param name="_connector"> a flattiverse connector that will be used for the login</param>
        public LoginControlViewModel(Flattiverse.Connector connector)
        {
            _connector = connector;

            LoginCmd = new LoginCommand(this);
            LogoutCmd = new LogoutCommand(this);

            _isLoggedIn = false;
            _userName = "Hoschi81";
            _password = "password!1";
        }
        #endregion constructor

        #region bindings
        private bool _isLoggedIn;
        private string _userName;
        private string _password;
        private string _accountName;
        private string _platform;

        public string AccountName
        {
            get { return _accountName; }
            private set
            {
                _accountName = value;
                base.RaisePropertyChanged("AccountName");
            }
        }

        public string Platform
        {
            get { return _platform; }
            private set
            {
                _platform = value;
                base.RaisePropertyChanged("Platform");
            }
        }

        public bool IsLoggedIn
        {
            get { return _isLoggedIn; }
            private set
            {
                _isLoggedIn = value;
                base.RaisePropertyChanged("IsLoggedIn");
            }
        }

        public string UserName
        {
            get { return _userName; }
            private set
            {
                _userName = value;
                base.RaisePropertyChanged("UserName");
            }
        }

        public string Password
        {
            get { return _password; }
            private set
            {
                _password = value;
                base.RaisePropertyChanged("Password");
            }
        }
        #endregion bindings
    }
}
